package com.suxin.websocket.pusher;

import com.suxin.websocket.model.RelationResponseModel;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Tang
 * @classname FriendRelationPusher
 * @description [  ]
 * @date 2022/3/24 17:05
 */
@Slf4j
public class FriendRelationPusher extends AbstractPusher<RelationResponseModel> {

//    @Resource
//    InvitationService invitationService;
//
//    @Resource
//    UserService userService;
//
//    @Resource
//    ActivityInfoService activityInfoService;

    public FriendRelationPusher() {
    }

    /**
     * 主动推，推给邀请了自己的用户
     */
    public void initiativePush(Integer uId) {
//        // 查询邀请记录,获取当前用户的邀请人id
//        InvitationRecord record = invitationService.getOne(
//                new QueryWrapper<InvitationRecord>().eq("invitee_id", uId)
//        );
        RelationResponseModel responseModel = new RelationResponseModel();
//        responseModel.setKey(record.getInviteeId().toString());
//        User user = userService.getUser(record.getInviteeId());
//        RelationResponse relationResponse = new RelationResponse();
//        BeanUtils.copyProperties(user, relationResponse);
//        relationResponse.setUId(user.getId());
//        responseModel.getResponseModels().add(relationResponse);
        // 推送过去
        push(responseModel);
    }

    /**
     * 连接时拉取需要推给自己的消息
     *
     * @param uId 要推送的用户id
     */
    public void onOpenPush(Integer uId) {
//        RelationResponseModel responseModel = new RelationResponseModel();
//        responseModel.setKey(uId.toString());
//        // 查询当前用户邀请的用户，有没有完成任务&关系没有确定的
//        List<InvitationRecord> records = invitationService.list(
//                new QueryWrapper<InvitationRecord>().eq("inviter_id", uId).isNull("relation_type")
//        );
//        ActivityInfo activityInfo = activityInfoService.getActiveActivity();
//        // 已经完成基础任务的被邀请用户
//        List<InviteeDTO> invitees = invitationService.getInvitee(records, activityInfo.getId());
//        invitees.stream()
//                .filter(InviteeDTO::getFinish)
//                .forEach(inviteeDTO -> {
//                    RelationResponse response = new RelationResponse();
//                    BeanUtils.copyProperties(inviteeDTO, response);
//                    response.setUId(inviteeDTO.getUId());
//                    responseModel.getResponseModels().add(response);
//                });
//        if (!CollectionUtils.isEmpty(responseModel.getResponseModels())) {
//            // 推送过去
//            push(responseModel);
//        }
    }

}